import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Finestra extends JFrame implements ActionListener {

    JPanel panel;
    private JButton redButton;
    private JButton greenButton;
    private JButton blueButton;
    JButton grayButton;

    public Finestra(String title) {

	super(title);
	redButton = new JButton("red");
	greenButton = new JButton("green");
	blueButton = new JButton("blue");
	grayButton = new JButton("gray");

	redButton.addActionListener(this);
	greenButton.addActionListener(this);
	grayButton.addActionListener(this);
	blueButton.addActionListener(this);

	setSize(800, 600);
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	setLayout(new FlowLayout());
	add(redButton);
	add(greenButton);
	add(blueButton);
	add(grayButton);

    }

    @Override
    public void actionPerformed(ActionEvent evt) {
	
    	if (evt.getSource()==redButton) {

	    getContentPane().setBackground(Color.red);
	}
	if (evt.getSource()==greenButton) {

	    getContentPane().setBackground(Color.green);
	}
	if (evt.getSource()==blueButton) {
	    getContentPane().setBackground(Color.blue);
	}
	if (evt.getSource()==grayButton) {
	    getContentPane().setBackground(Color.gray);
	}
	repaint();
	}
}

public class FourButtonsTester {

    public static void main(String[] args) {

	Finestra principal = new Finestra("Programa de colors");
	principal.setVisible(true);
    }
}
